﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Supplier;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Supplier
{
    /// <summary>
    /// 根据id查看对应的联系人信息
    /// </summary>
    public class ContactPersonsSelIdHandler : IRequestHandler<ContactPersonsSelIdCommand, THE_WIND_RISES.Common.Dtos.Result>
    {   
        
        /// <summary>
        /// 联系人信息
        /// </summary>
        private readonly IBaseRepositoryGet<ContactPersons> contactPersonsRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="contactPersonsRepository"></param>
        public ContactPersonsSelIdHandler(IBaseRepositoryGet<ContactPersons> contactPersonsRepository)
        {
            this.contactPersonsRepository = contactPersonsRepository;
        }

        public async Task<Result> Handle(ContactPersonsSelIdCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            try
            {
                string sql = $"select * from ContactPersons where ContactPersonsId={request.ContactPersonsId}";

                var list = contactPersonsRepository.GetAll(sql, default);

                if (list != null)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Data = list;
                    result.Msg = "传值成功";
                }
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
    }
}
